BitSet Class Reference
[Abstract Data Types]

Bitset - A collection of bits. More...

#include <fbitset.h>

Inheritance diagram for BitSet:
Inheritance graph
[legend]

Public Types

enum  ReturnTypes { kEmptySize = -2L, kBitNotFound = -1L }

Public Member Functions

 BitSet ()
 Default constructor (size is 0).
 BitSet (uint32 size)
 Constructor with a given size (number of wanted bits).
 BitSet (const BitSet &)
 Copy constructor.
virtual ~BitSet ()
 Virtual destructor.
BitSetoperator= (const BitSet &)
 Assignment operator.
bool operator== (const BitSet &)
 The equality operator.
bool operator!= (const BitSet &)
 The inequality operator.
BitSetoperator&= (const BitSet &toAnd)
 Bitwise and (AND), both bitsets needs to have the same size, otherwise nothing happens.
BitSetoperator|= (const BitSet &toOr)
 Bitwise inclusive or (OR), both bitsets needs to have the same size, otherwise nothing happens.
BitSetoperator^= (const BitSet &toXOr)
 Bitwise exclusive or (XOR), both bitsets needs to have the same size, otherwise nothing happens.
void setSize (uint32 size)
 Resize to then number of bits that the bitset can hold, resize to 0 is allowed (free all), allocate memory is rounded to next kChunkSize.
uint32 getSize () const
 Return the current size of the BitSet.
void setBit (uint32 which)
 Sets the bit (at 'which' position) to 1; resizes the bitSet if necessary when which > size.
void clearBit (uint32 which)
 Sets the bit (at 'which' position) to 0; resizes the bitSet if necessary when which > size.
void toggleBit (uint32 which)
 Changes the bits value (flip: 0=>1, 1=>0); resizes the bitSet if necessary when which > size.
void setAll ()
 Sets all bits to 1.
void clearAll ()
 Sets all bits to 0 (clears every bit).
bool getBit (uint32 which) const
 Returns if the bit (at 'which' position) is set to 1.
bool isEmpty () const
 Returns true, if no bit is set (all 0).
uint32 countSetBits (int32 toPos=-1) const
 Return the count of set bits from 0 to toPos position.
int64 getFirstSet () const
 Return the first found set bit (from 0 to size-1) or see ReturnTypes.
int64 getFirstNotSet () const
 Return the first found NOT set bit (from 0 to size-1) or see ReturnTypes.
int64 getLastSet () const
 Return the last found set bit (from size-1 to 0) or see ReturnTypes.

Protected Types

typedef uint32 BSChunkType

Protected Member Functions

virtual void onChange ()
 is called when bits are changed, derived classes can overwrite this.
uint32 getChunkCount () const
 Return the count of chunk currently used and allocate.
BSChunkType getChunk (uint32 n) const
 Return the wanted chunk by index (return 0 if not available).
void setChunk (uint32 n, BSChunkType chunk)
 Set/replace a given chunk.

Static Protected Attributes

static const uint32 kChunkSize = sizeof (BSChunkType) * 8
static const uint32 kChunkByteSize = sizeof (BSChunkType)
static const BSChunkType kFullChunk = 0xfffffffful

Detailed Description

Bitset - A collection of bits.

Individual indexed bits can be examined, set, or cleared. Its size is variable (grows as needed). One BitSet may be used to modify the contents of another BitSet through logical AND, logical inclusive OR, and logical exclusive OR operations. By default, all bits in the set initially have the value 0 (Not Set).

Note:
Logical operations:
	0 AND 0 = 0		0 OR 0 = 0		0 XOR 0 = 0
	0 AND 1 = 0		0 OR 1 = 1		0 XOR 1 = 1
	1 AND 0 = 0		1 OR 0 = 1		1 XOR 0 = 1
	1 AND 1 = 1		1 OR 1 = 1		1 XOR 1 = 0

Member Typedef Documentation

typedef uint32 BSChunkType [protected]

Member Enumeration Documentation

Enumerator:
kEmptySize 

Return when the bitSet is empty when searching for a bit.

kBitNotFound 

Searched bit not found.


Constructor & Destructor Documentation

BitSet (  ) 

Default constructor (size is 0).

BitSet ( uint32  size  ) 

Constructor with a given size (number of wanted bits).

BitSet ( const BitSet from  ) 

Copy constructor.

~BitSet (  )  [virtual]

Virtual destructor.


Member Function Documentation

BitSet & operator= ( const BitSet from  ) 

Assignment operator.

bool operator== ( const BitSet toCompare  ) 

The equality operator.

bool operator!= ( const BitSet toCompare  ) 

The inequality operator.

BitSet & operator&= ( const BitSet toAnd  ) 

Bitwise and (AND), both bitsets needs to have the same size, otherwise nothing happens.

BitSet & operator|= ( const BitSet toOr  ) 

Bitwise inclusive or (OR), both bitsets needs to have the same size, otherwise nothing happens.

BitSet & operator^= ( const BitSet toXOr  ) 

Bitwise exclusive or (XOR), both bitsets needs to have the same size, otherwise nothing happens.

void setSize ( uint32  size  ) 

Resize to then number of bits that the bitset can hold, resize to 0 is allowed (free all), allocate memory is rounded to next kChunkSize.

uint32 getSize (  )  const [inline]

Return the current size of the BitSet.

void setBit ( uint32  which  ) 

Sets the bit (at 'which' position) to 1; resizes the bitSet if necessary when which > size.

void clearBit ( uint32  which  ) 

Sets the bit (at 'which' position) to 0; resizes the bitSet if necessary when which > size.

void toggleBit ( uint32  which  ) 

Changes the bits value (flip: 0=>1, 1=>0); resizes the bitSet if necessary when which > size.

void setAll (  ) 

Sets all bits to 1.

void clearAll (  ) 

Sets all bits to 0 (clears every bit).

bool getBit ( uint32  which  )  const

Returns if the bit (at 'which' position) is set to 1.

bool isEmpty (  )  const

Returns true, if no bit is set (all 0).

uint32 countSetBits ( int32  toPos = -1  )  const

Return the count of set bits from 0 to toPos position.

int64 getFirstSet (  )  const

Return the first found set bit (from 0 to size-1) or see ReturnTypes.

int64 getFirstNotSet (  )  const

Return the first found NOT set bit (from 0 to size-1) or see ReturnTypes.

int64 getLastSet (  )  const

Return the last found set bit (from size-1 to 0) or see ReturnTypes.

virtual void onChange (  )  [inline, protected, virtual]

is called when bits are changed, derived classes can overwrite this.

uint32 getChunkCount (  )  const [inline, protected]

Return the count of chunk currently used and allocate.

BitSet::BSChunkType getChunk ( uint32  n  )  const [protected]

Return the wanted chunk by index (return 0 if not available).

void setChunk ( uint32  n,
BitSet::BSChunkType  chunk 
) [protected]

Set/replace a given chunk.


Field Documentation

const uint32 kChunkSize = sizeof (BSChunkType) * 8 [static, protected]
const uint32 kChunkByteSize = sizeof (BSChunkType) [static, protected]
const BSChunkType kFullChunk = 0xfffffffful [static, protected]
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Empty

Copyright ©2013 Steinberg Media Technologies GmbH. All Rights Reserved.